<template>
  <div class="pd30 produceFactory">
    <div class="panelWrap">
      <div class="title flex flexac flexjcsb fs14 cfff fwb pl p-r-20">
        <div>维保评价管理</div>
      </div>
      <div class="con">
        <div class="con-row flex flexac pl search-box">
          <div class="flex flexac">
            <el-input v-model="orderId" class="co-input" placeholder="请输入工单ID..." />
          </div>
          <div class="groupbtn flex m-l-40 ">
            <el-button class="flex flexac m-r-20 fs14" size="small" type="warning" @click="getFeedback"><i class="co-i" /><span class="search1">查 询</span></el-button>
            <el-button class="co-empty flexcenter m-l-25" type="info" @click="handleEmptySearch"><i class="iconfont icon-qingkong" />清 空</el-button>
          </div>
        </div>
        <div class="con-row flex flexac flexjcsb pl">
          <el-button class="defaultbtn" type="primary" @click="handleRefresh"><i class="el-icon-refresh" :class="refresh?'goRefresh':''" />刷 新</el-button>
          <div class="m-r-25 flex">
            <!-- <el-button class="defaultbtn" type="primary" @click="handleAdd"><i class="el-icon-circle-plus-outline" />添加</el-button> -->
            <el-button class="defaultbtn" type="primary" @click="handleExportExcel"><i class="iconfont icon-wenjiandaochu" />导出</el-button>
            <div class="pre m-l-10">
              <el-button class="defaultbtn pre" type="primary" @click="handleSenior('field')"><i class="iconfont icon-shezhi" />字段
              </el-button>
              <div class="selectUl" :class="seniorSet.field?'showSelectUl':'hideSelectUl'">
                <div v-for="(item,i) in tablehead" :key="i" class="li">
                  <el-checkbox v-model="item.isShow">{{ item.label }}</el-checkbox>
                </div>
              </div>
            </div>
            <div class="pre m-l-10">
              <el-button class="defaultbtn" type="primary" @click="handleSenior('sortable')"><i class="iconfont icon-shezhi" />排序</el-button>
              <div class="selectUl" :class="seniorSet.sortable?'showSelectUl':'hideSelectUl'">
                <div v-for="(item,i) in tablehead" v-if="item.isShow" :key="i" class="li">
                  <el-checkbox v-model="item.sortable">{{ item.label }}</el-checkbox>
                </div>
              </div>
            </div>
            <!-- <el-button class="defaultbtn" @click="handleExportExcel" type="primary"><i class="iconfont icon-shezhi"></i>固定</el-button> -->
          </div>
        </div>

        <el-table
          id="contList"
          ref="contList"
          class="con-table"
          type="expand"
          :data="contList"
          style="width: 100%"
          highlight-current-row
        >
          <template v-for="item in tablehead">
            <el-table-column v-if="item.isShow" :key="item.index" :width="item.width" align="center" :sortable="item.sortable" :show-overflow-tooltip="true" :prop="item.prop" :label="item.label" />
          </template>

          <el-table-column align="center" prop="name" label="基本操作" width="190">
            <template slot-scope="scope">
              <!-- <el-button class="defaultbtn ba-btn" type="primary" plain size="mini" @click="handleEdit(scope.$index, scope.row)">
                <i class="el-icon-edit" />
                编辑</el-button> -->
              <!-- <el-button type="danger" class="defaultbtn ba-btn" @click="handleDeleteBtn(scope.$index, scope.row)"><i class="el-icon-delete-solid" />删除</el-button> -->
            </template>
          </el-table-column>
        </el-table>
        <el-pagination class="paginationWrap flex " :current-page="paging.currentPage" :page-sizes="paging.pageSizeArr" :page-size="paging.pageSize" layout="total, sizes, prev, pager, next, jumper" :total="paging.total" @size-change="handleSizeChange" @current-change="handleCurrentChange" />
      </div>
    </div>
    <Feedback v-model="feedbackVisible" :data="feedback" :is-edit="isEdit" @handleRefresh="handleRefresh" @handleCloseDialog="handleCloseDialog" />
  </div>
</template>

<script>

import Feedback from './dialog/index'
import { feedbackQueryList } from '@/api/maintenance/orderfeedback'
import { showNotice, formatDateTime } from '@/utils/toolclass'
import { elevatorQueryList } from '@/api/elevator/elevator'

export default {
  name: 'Evaluation',
  components: { Feedback },
  props: {},
  data() {
    return {
      paging: {
        currentPage: 1,
        pageSize: 10,
        pageSizeArr: [10],
        total: 0
      },

      contList: [],
      orderId: '',
      feedbackVisible: false,
      feedback: {},
      isEdit: false,
      refresh: false,
      seniorSet: {
        'field': false,
        'sortable': false
      },
      tablehead: [
        // {
        //   index: 0,
        //   prop: 'elevatorId',
        //   label: '电梯信息',
        //   sortable: false,
        //   fixed: true,
        //   isShow: true
        // },
        {
          index: 0,
          prop: 'registerCode',
          label: '注册代码',
          sortable: false,
          fixed: true,
          isShow: true
        },
        {
          index: 1,
          prop: 'rescueCode',
          label: '位置码',
          width: '100',
          sortable: false,
          fixed: true,
          isShow: true
        },
        // {
        //   index: 1,
        //   prop: 'name',
        //   label: '维保单位',
        //   sortable: false,
        //   fixed: true,
        //   isShow: true
        // },
        {
          index: 2,
          prop: 'name',
          label: '维保计划',
          sortable: false,
          fixed: true,
          isShow: true
        },
        {
          index: 3,
          prop: 'contractNumbe',
          label: '合同编号',
          sortable: false,
          fixed: true,
          isShow: true
        },
        {
          index: 4,
          prop: 'type',
          label: '维保方式',
          width: '100',
          sortable: false,
          fixed: true,
          isShow: true
        },
        {
          index: 5,
          prop: 'appointmentDate',
          label: '预约时间',
          sortable: false,
          fixed: true,
          isShow: true
        },
        {
          index: 6,
          prop: 'exceptDate',
          label: '应完成时间',
          sortable: false,
          fixed: true,
          isShow: true
        },
        // {
        //   index: 7,
        //   prop: 'remark',
        //   label: '维保类型',
        //   width: '80',
        //   sortable: false,
        //   fixed: true,
        //   isShow: true
        // },
        {
          index: 8,
          prop: 'state',
          label: '状态',
          width: '80',
          sortable: false,
          fixed: true,
          isShow: true
        }
      ]

    }
  },
  computed: {},
  watch: {},
  created() {
    this.getFeedback()
  },
  mounted() {
    this.$storage.set('upUrl', JSON.stringify({ 'path': '/rescue/evaluation' }))
  },
  methods: {
    handleSenior(type) {
      if (type === 'field') {
        this.seniorSet.field = !this.seniorSet.field
      }
      if (type === 'sortable') {
        this.seniorSet.sortable = !this.seniorSet.sortable
      }
    },

    handleExportExcel() {
      require.ensure([], () => {
        const { export_json_to_excel } = require('@/excel/Export2Excel')
        const tHeader = ['电梯ID', '电梯型号', '备注']
        const filterVal = ['id', 'name', 'remark']
        const data = this.formatJson(filterVal, this.contList)
        export_json_to_excel(tHeader, data, '电梯型号列表(' + formatDateTime().ymd) + ')'
      })
    },
    formatJson(filterVal, jsonData) {
      return jsonData.map(v => filterVal.map(j => v[j]))
    },
    handleRefresh() {
      this.refresh = true
      this.getFeedback()
      setTimeout(() => {
        this.refresh = false
      }, 1200)
    },
    getFeedback() {
      feedbackQueryList(1, this.paging.currentPage, this.paging.pageSize).then(res => {
        // console.log(res)
        if (res.code === '000000') {
          // console.log(res)
          this.paging = {
            currentPage: res.pager.pageIndex,
            pageSize: res.pager.pageSize,
            total: res.pager.totalSize
          }
        }
      })
    },
    handleEmptySearch() {
      this.orderId = ''
      this.getFeedback()
    },
    handleEdit(index, row) {
      this.feedbackVisible = true
      this.isEdit = true
      // console.log(row)
      elevatorQueryList('', '', '', 1, 10000, '', '', '', '').then(res => {
        if (res.code === '000000') {
          // console.log(res)
          const elevaList = res.data.filter(item => {
            if (row.elevatorId === item.id) {
              return item
            }
          })
          this.feedback = {
            appointmentDate: row.appointmentDate,
            contractId: row.contractId,
            contractNumbe: row.contractNumbe,
            crtDate: row.crtDate,
            crtOpr: row.crtOpr,
            elevatorId: row.elevatorId,
            exceptDate: row.exceptDate,
            finishDate: row.finishDate,
            id: row.id,
            lstEdtDate: row.lstEdtDate,
            lstEdtOpr: row.lstEdtOpr,
            name: row.name,
            orgId: row.orgId,
            registerCode: row.registerCode,
            rescueCode: row.rescueCode,
            state: row.state,
            type: row.type,
            version: row.version,
            elevList: elevaList
          }
        }
      })
    },
    handleAdd() {
      this.feedbackVisible = true
      this.isEdit = false
      this.feedback = {
        crtDate: '', // 创建时间
        crtOpr: '', // 创建人
        id: 0, // ID
        lstEdtDate: '', // 最后修改时间
        lstEdtOpr: '', // 最后修改人ID
        orderId: '', // 工单Id
        orgId: '', // 机构id
        otherDesc: '', // 其他建议
        score: '', // 分数
        servicesQuality: '', // 服务质量
        servicesState: '', // 服务态度
        version: '' // 版本号
      }
    },
    handleDeleteBtn(index, row) {
      this.$alert('这个操作会删除和它相关联的所有数据,确定要删除吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        showCancelButton: true,
        callback: action => {
          if (action === 'confirm') {
            this.handleDelete(row.id)
          }
        }
      })
    },
    handleDelete(id) {
      miPlanDelete(id).then((res) => {
        if (res.code === '000000') {
          showNotice('success', '提示', '删除成功')
          this.getFeedback()
        } else {
          if (res.msg === '失败') {
            showNotice('error', '提示', '删除失败')
          } else {
            // showNotice('error', '提示', res.msg)
          }
        }
      })
    },
    handleCloseDialog() {
      this.feedbackVisible = !this.feedbackVisible
    },
    handleSizeChange(val) {
      this.paging.pageSize = val
      this.getFeedback()
    },
    handleCurrentChange(val) {
      this.paging.currentPage = val
      this.getFeedback()
    }
  }
}
</script>

<style lang="scss">
</style>
